% B0=Calgob(BMvec,param,wr,xr)
% Calculates the value of becoming unemployed (month zero)
% (by summing the stream of unemployment benefits for months 1-12 (ALG1))
% inputs:
% - set of wage levels wr 
% - and xN long-run (stationary) unemp values BMvec,
% - set of transition parameters & discount rate param
function B0=Calgob(BMvec,param,wr,xr)
% vector of wages here should be in horizontal format (1,length(wr))
wN=length(wr);
if size(wr,1)>size(wr,2)
    wr=wr';
end
lamNC=param.lamNC(xr);
lamC=param.lamC(xr);
BM=BMvec(xr);
r=param.rm;

% set unemployment benefits - 60% of income in first 12 months
% allow for vector of wages (then columns are different wages)
bm=NaN(13,wN);
bm(1:12,:)=0.6.*ones(12,1)*wr; 
bm(13,:)=param.bM;

Bm=NaN(12,wN);
    for tx=1:12
        tosum=NaN(tx,wN);
        for sx=0:tx-1
            tosum(sx+1,:)=((1-lamNC-lamC)./(1+r))^(sx).*((bm(13-(tx-sx),:)-bm(13,:))/(1+r));
        end
        Bm(13-tx,:) = BM + sum(tosum,1);
    end
B0=Bm(1,:);
end
